<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/23/023
 * Time: 20:51
 */

namespace app\Lib\Model\User;


use app\Lib\Model\AdminAuth\GetAuthorization\GetUserAuth;
use app\Lib\Model\DbModel\UserBase;

class GetUserInfo
{
    private $user;
    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function run(){
        $table =  new UserBase();
        $userModel = $this->user;
        $auth = (new GetUserAuth($userModel))->run();
        $newAuth = [];
        if(!empty($auth)){
            foreach ($auth as $k=>$v){
                /**@var \app\Lib\Model\AdminAuth\MenuAuth $v*/
                $newAuth[$v->getMenuId()]= $v->getMenuId();
            }
        }
        $data= [
            $table->_id=>$userModel->getUid(),
            'account'=>$userModel->getAccount(),
            'nickName'=>$userModel->getNickName(),
            'weixin'=>$userModel->getWeiXin(),
            'birthday'=>$userModel->getBirthday(),
            'mobilephone'=>$userModel->getPhone(),
            'roleId'=>$userModel->getRoleClass()->getRoleId(),
            'sex'=>$userModel->getSex(),
            'account_status'=>$userModel->isAllowLogin()?'1':'0',
            'auth'=>$newAuth,
        ];
        return $data;
//        account
//        mobilephone
//        weixin
//        nickName
//        birthday
//        auth
//        id
//        roleId
//        account_status
//        sex
    }
}